var util = require('util');

// 系统配置
system = {
    user:'app100712667',
    home:'/data/home/app100712667',
}

// 平台配置
platform = {
    id:1,
    name:'qzone',
    exchange_rate:0.01,
    dip:{port:8002},
    gm: {
        key:'fuckthehacker',
        profiler:{port:8003},
        transfer:{port:8003},
    }
}

// MYSQL配置
mysql = {
    ip:'1.4.12.73',
    port:1025,
    user:'root',
    password:'molingkeji123',
    charset:'latin1',
    gm: {
        ip:'1.4.12.73', 
        port:1026,
    }
},

// 合服配置
merge = {
    mongo:{ip:'127.0.0.1', port:27017, },
},

// 服务器配置
server = {
    host:{
        'mid':{ip:'10.190.168.48', url:'http://test.app100712667.twsapp.com',},
        'php':{ip:'10.207.142.107',},
        'log':{ip:'10.190.169.28',},
        'cache':{ip:'10.207.151.192', redis:{bind:'10.207.151.192', port:6397}},
        'db1':{ip:'10.207.148.228', mongo:{port:17027, slave:'dbb1'}},
        'db2':{ip:'10.221.4.111', mongo:{port:17027, slave:'dbb2'}},
        'dbb1':{ip:'10.207.138.189', mongo:{port:17027}},
        'dbb2':{ip:'10.207.144.204', mongo:{port:17027}},
        'c1':{ip:'10.207.144.132', cloud:[[1,4],], cloud_rank:[[1,4],]},
        'c2':{ip:'10.207.147.13', cloud:[[5,10],], cloud_rank:[[5,10],]},
        'c3':{ip:'10.190.160.18', cloud_mine:[[1,4],], champsbattle:[[9,16],], cloud_battle:[[2,6],]},
        'c4':{ip:'10.207.137.161', cloud_mine:[[5,20]], cloud_battle:[[1,1]], champsbattle:[[1,8],]},
        'un1':{ip:'10.207.248.183', universe:[[1,40],]},
        'un2':{ip:'10.207.141.216', universe:[[41,100],]},
        'w01':{ip:'10.190.161.13', url:'http://qzone1.app100712667.twsapp.com', game:[[1,6],]},
        'w78':{ip:'10.190.166.138', url:'http://qzone78.app100712667.twsapp.com', game:[[7,259],]},
        'w80':{ip:'10.190.161.153', url:'http://qzone80.app100712667.twsapp.com', game:[[260,569],]},
        'w63':{ip:'10.207.159.105', url:'http://qzone63.app100712667.twsapp.com', game:[[570,807],]},
        'w75':{ip:'10.182.7.237', url:'http://qzone75.app100712667.twsapp.com', game:[[808,873],]},
        'w79':{ip:'10.190.168.211',},
        'w81':{ip:'10.190.163.239', url:'http://qzone81.app100712667.twsapp.com', game:[[874,884],]},
        'w82':{ip:'10.190.161.188', url:'http://qzone82.app100712667.twsapp.com', game:[[885,895],]},
        'w83':{ip:'10.207.138.18', url:'http://qzone83.app100712667.twsapp.com', game:[[896,906],]},
        'w76':{ip:'10.182.30.14', url:'http://qzone76.app100712667.twsapp.com', game:[[907,917],]},
        'w85':{ip:'10.190.162.8', url:'http://qzone85.app100712667.twsapp.com', game:[[918,928],]},
        'w86':{ip:'10.190.160.56', url:'http://qzone86.app100712667.twsapp.com', game:[[929,939],]},
    },
},

game = {
    offset:1,
    db_prefix:'sanguo',
    path_prefix:'s',
},

cloud = {
    db_prefix:'cloud',
    path_prefix:'cloud',
},

cloud_rank = {
    db_prefix:'cloud_rank',
    path_prefix:'cloud_rank',
},

cloud_mine = {
    db_prefix:'cloud_mine',
    path_prefix:'cloud_mine',
},

cloud_battle = {
    db_prefix:'cloud_battle_world',
    path_prefix:'cbatlle_world',
},

champsbattle = {
    db_prefix:'champsbattle',
    path_prefix:'champsbattle',
},

cloudarena = { 
    db_prefix:'cloudarena',
    path_prefix:'cloudarena',
}
,
universe = {
    db_prefix:'universe',
    path_prefix:'u',
},


// 游戏服的支付监听端口
game.pay_port = function(sid) {
    return 6001+(+sid);
}

// 游戏服的登录监听端口
game.gateway_port = function(sid) {
    sid = +sid;
    if (sid <= 1) {
        return 8002;
    } else if (sid <= 6) {
        return 8005;
    }

    return 7001+(+sid);
}

// 游戏服所在数据库主机Id
game.db_host_id = function(sid) {
    sid = +sid;
    if (sid <= 103) {
        return 'db1';
    } else {
        return 'db2';
    }
}

// 游戏服所在云服sid
game.cloud_sid = function(sid) {
    return Math.ceil((+sid)/100);
}

// 游戏服所在云服sid
game.cloud_rank_sid = function(sid) {
    return Math.ceil((+sid)/100);
}

// 游戏服所在跨服金矿服sid
game.cloud_mine_sid = function(sid) {
    return Math.ceil((+sid)/50);
}

// 游戏服所在决战天下服sid
game.cloud_battle_sid = function(sid) {
    sid = +sid;
    var csid;
    var groups = [891];
    for (var i = groups.length; i > 0 && sid <= groups[i - 1]; --i) {
        csid = i;
    }
    return csid;
}

//游戏服所在王者战场服sid
game.champsbattle_sid = function(sid) {
    sid = +sid;
    var csid;
    var groups = [260,721,877,905,913];
    for (var i = groups.length; i > 0 && sid <= groups[i - 1]; --i) {
        csid = i;
    }
    return csid;
}

// 游戏服所在跨服擂台服sid
game.cloudarena_sid = function(sid) {
    sid = +sid;
    var csid;
    var groups = [];
    for (var i = groups.length; i > 0 && sid <= groups[i - 1]; --i) {
        csid = i;
    }
    return csid;
}
// 游戏服所在群雄争霸服sid
game.universe_sid = function(sid) {
    sid = +sid;
    if (sid >= 381 && sid <= 385) {
        return 38;
    } else if (sid >= 386 && sid <= 390) {
        return 40;
    }

    return Math.ceil(sid/10);
}




// 云服的监听端口
cloud.port = function(sid) {
    sid = +sid;
    return 5000+sid;
}

// 云服所在数据库主机Id
cloud.db_host_id = function(sid) {
    return 'db1';
}

// 云服的监听端口
cloud_rank.port = function(sid) {
    sid = +sid;
    return 5100+sid;
}

// 云服所在数据库主机Id
cloud_rank.db_host_id = function(sid) {
    return 'db1';
}

// 跨服金矿的监听端口
cloud_mine.port = function(sid) {
    sid = +sid;
    return 5300+sid;
}

// 跨服金矿所在数据库主机Id
cloud_mine.db_host_id = function(sid) {
    return 'db1';
}

// 决战天下的监听端口
cloud_battle.port = function(sid) {
    sid = +sid;
    return 5200+sid;
}

// 决战天下所在数据库主机Id
cloud_battle.db_host_id = function(sid) {
    return 'db1';
}

// 王者战场的监听端口
champsbattle.port = function(sid) {
    sid = +sid;
    return 5400+sid;
}

// 王者战场所在数据库主机Id
champsbattle.db_host_id = function(sid) {
    return 'db1';
}

// 跨服擂台的监听端口
cloudarena.port = function(sid) {
    sid = +sid;
    return 13100+sid;
}

// 跨服擂台所在数据库主机Id
cloudarena.db_host_id = function(sid) {
    return 'mid';
}

// 群雄争霸的监听端口
universe.port = function(sid) {
    sid = +sid;
    return 5000+sid;
}

// 雄争霸所在数据库主机Id
universe.db_host_id = function(sid) {
    return 'db1';
}




//////////////////////////////////////////////////////////
// 运行时配置项
runtime = {
    // 跨服充值排行榜服务器开启时间限制
    ServerPayRankServerTime: '2014:12:10:23:0:0',

    // 首次决战下开启时间
    gameFirstCloudBattleTime: function(sid) {
        var cloudBattleSid = game.cloud_battle_sid(sid);
        if (cloudBattleSid) {
            return '2014:01:12:20:30:00';
        } else {
            return '2020:01:12:20:30:00';
        }
    },

    // 首次群雄争霸开启时间(周六18点)
    gameFirstUniverseTime: function(sid) {
        sid = +sid;
        var firstTime = '';
        if (sid <= 120) {
            firstTime = '2013:11:09:18:00:00';
        } else if (sid <= 150) {
            firstTime = '2013:12:07:18:00:00';
        } else if (sid <= 190) {
            firstTime = '2013:12:21:18:00:00';
        } else if (sid <= 220) {
            firstTime = '2014:01:04:18:00:00';
        } else if (sid <= 260) {
            firstTime = '2014:01:25:18:00:00';
        } else if (sid <= 350) {
            firstTime = '2014:03:08:18:00:00';
        } else if (sid <= 400) {
            firstTime = '2014:03:29:18:00:00';
        } else if (sid <= 430) {
            firstTime = '2014:04:12:18:00:00';
        } else if (sid <= 500) {
            firstTime = '2014:07:12:18:00:00';
        } else if (sid <= 580) {
            firstTime = '2014:09:27:18:00:00';
        } else if (sid <= 600) {
            firstTime = '2014:10:18:18:00:00';
        } else if (sid <= 680) {
            firstTime = '2015:01:10:18:00:00';
        } else if (sid <= 750) {
            firstTime = '2015:06:20:18:00:00';
        } else if (sid <= 880) {
            firstTime = '2016:03:26:18:00:00';
        }
        return firstTime;
    },
    
    //统奖励配置
    getSystemReward: function(sid) {
        sid = +sid;
        if (sid == 2 || sid == 321 || sid == 449 || sid == 503) {
            return {id:242, time:'2016:08:05:10:00:00'};
        } if (sid == 260) {
            return {id:237, time:'2016:07:08:10:00:00'};
        } else if (sid >= 721 && sid <= 903) {
            return {id:233, time:'2016:06:25:10:00:00'};
        } else { //default
            return {id:234, time:'2016:06:25:10:00:00'};
        }
    },
}





exports.system = system;
exports.platform = platform;
exports.mysql = mysql;
exports.server = server;
exports.merge = merge;
exports.game = game;
exports.cloud = cloud;
exports.cloud_rank = cloud_rank;
exports.cloud_mine = cloud_mine;
exports.cloud_battle = cloud_battle;
exports.champsbattle = champsbattle;
exports.universe = universe;
exports.runtime = runtime;
exports.cloudarena = cloudarena;
